<template>
  <div class="main">
    <div class="active">
      <span class="iconfont">&#xe600;</span>最新活动:
    </div>
    <div class="goods" v-for="(item,index) of goodsList" :key="item.id">
      <div class="goods-img">
        <img class="goods-img-content" :src="item.imgUrl">
      </div>
      <div class="price">
        <p class="goods-desc">{{item.desc}}</p>
        <div class="goods-money">{{item.money}}元/份</div>
        <div class="select">
          <img
            src="http://res.4008823823.com.cn/kfcios/Html/res/images/minus_icon_2.gif"
            @click="jian(index)"
          >
          <input class="goods-num" type="text" :value="item.num">
          <img
            src="http://res.4008823823.com.cn/kfcios/Html/res/images/add_icon_2.gif"
            @click="up(index)"
          >
        </div>
        <button
          class="join"
          @click="dinggou(index)"
          :disabled=" item.state == false"
          :class="item.state == false ? 'active1' :''"
        >订购</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'IndexShop1',
  props: {},
  type: {
    type: String,
    default: 0
  },
  data () {
    return {
      goodsList: [
        {
          id: '0001',
          imgUrl: 'https://img.4008823823.com.cn/kfcios/Version/609_596217.jpg',
          desc: 'WOW桶随心配',
          money: '98.5',
          num: '1',
          state: false
        },
        {
          id: '0002',
          imgUrl: 'https://img.4008823823.com.cn/kfcios/Version/621_627383.jpg',
          desc: '花花五一世界桶',
          money: '108.0',
          num: '1',
          state: false
        },
        {
          id: '0003',
          imgUrl: 'https://img.4008823823.com.cn/kfcios/Version/618_623711.jpg',
          desc: '翅桶嫩牛五方辣堡餐',
          money: '89.0',
          num: '1'
        },
        {
          id: '0004',
          imgUrl: 'https://img.4008823823.com.cn/kfcios/Version/609_593771.jpg',
          desc: '辣鸭肉卷人气明星餐',
          money: '39.0',
          num: '1'
        },
        {
          id: '0005',
          imgUrl: 'https://img.4008823823.com.cn/kfcios/Version/604_585870.jpg',
          desc: '吮指原味鸡',
          money: '58.0',
          num: '1'
        },
        {
          id: '0006',
          imgUrl: 'https://img.4008823823.com.cn/kfcios/Version/604_583308.jpg',
          desc: '原味鸡波纹霸薯套餐',
          money: '39.0',
          num: '1'
        }
      ]
    }
  },
  methods: {
    up (num) {
      this.goodsList[num].num++
    },
    jian (num) {
      if (this.goodsList[num].num < 2) {
        this.goodsList[num].num = 1
        return
      }
      this.goodsList[num].num--
    },
    dinggou (num) {
      this.$store.state.list.push(this.goodsList[num])
    }
  }
}
</script>

<style lang="stylus" scoped>
.main {
  width: 33%;
  height: 11rem;
  display: flex;
  flex-wrap: wrap;
  margin-left: 0.3rem;
  margin-top: 0.15rem;
  padding-bottom: 1rem;

  .active {
    width: 100%;
    height: 0.4rem;
    background: rgb(240, 240, 240);
    padding-top: 0.1rem;
  }

  .goods {
    overflow: hidden;
    float: left;
    width: 31.93%;
    height: 50%;
    margin-right: 0.1rem;
    border: 1px solid #d0d0d0;

    .goods-img {
      top: 0;
      left: 0;
      right: 0;
      bottom: 4rem;
      box-sizing: border-box;

      .goods-img-content {
        height: 100%;
        width: 100%;
      }
    }

    .price {
      width: 100%;
      height: 22%;

      .goods-desc {
        width: 100%;
        height: 30%;
        font-weight: bold;
        font-size: 13px;
        margin-top: 0.05rem;
      }

      .goods-money {
        width: 100%;
        height: 30%;
        margin-top: 0.5rem;
      }

      .select {
        width: 100%;
        height: 40%;
        margin-top: 0.1rem;
        display: flex;
        flex-direction: row;

        .goods-num {
          width: 30%;
          height: 90%;
          margin-left: 0.1rem;
          margin-right: 0.1rem;
          text-align: center;
          border: 1px solid #cccccc;
        }
      }

      .join {
        width: 50%;
        height: 40%;
        background: red;
        color: white;
        font-size: 16px;
        font-weight: bold;
        margin-left: 0.8rem;
        margin-top: 0.2rem;
      }

      .active1 {
        background: gray;
      }
    }
  }
}
</style>
